%% deploy sensors on sizeX, sizeY area
function [S_Map, D_Map] = put_sensors(N,sizeX,sizeY,BaseX,BaseY,random)
%
% ____________ INPUT ___________
% N         - number of nodes
% sizeX     - X dimension of area
% sizeY     - X dimension of area
% BaseX     - x cooridinate of base station (BS),(as N+1 node)
% BaseY     - y cooridinate of base station (BS),(as N+1 node)
% random    - randomize seed if random=0 then fully randomize
%                               else start randomizing from choosen setting point=random
%
% ____________ OUTPUT __________
%------- S_Map = Sensors_Map -------------
% Sensors_Map(:,1) - X position
% Sensors_Map(:,2) - Y position
% Sensors_Map(:,3) - current energy
% Sensors_Map(:,4) - max energy
% Sensors_Map(:,5) - stan czujnika (nieznany 0, zwykly 1, CH 2)
% Sensors_Map(:,6) - stan czujnika dla wizualizacji
%
%------- D_Map = Distances_Map -----------
% Map  [NxN] odleglosci euklidesowe miedzy wezlami


    %% Random algorithm initialization
    if random==0
        rand('state',sum(100*clock));  %RAND is deprecated
        %RandStream('mt19937ar','seed',sum(100*clock)); % fully randomizing deploy
    else
        rand('state',random);         %RAND is deprecated
        %RandStream.setDefaultStream(RandStream('mt19937ar')); % start randomizing from random setting point
    end

    %% Nodes placing
    S_Map(:,1:2)=round(rand(N,2)*(sizeX-1))+1;

    S_Map(N+1,1)=BaseX;
    S_Map(N+1,2)=BaseY;

    %% dodatkowe
    S_Map(:,3)=300;     %max(20,100*rand(1,1));      %stan aktualny energii wezl�w
    S_Map(:,4)=300;     %stan maksymalny energii wezl�w
    S_Map(:,5)= 0;      % same czujniki nieznane a nie zwykle (1) czy ClusterHeady (2)

    %% distance map calculating
    D_Map(1,1) = sqrt((S_Map(1,1)-BaseX)^2+(S_Map(1,2)-BaseY)^2); % odleglosc wezla nr 1 od punktu bazowego SINK
    for li = 2:N    % wyznaczamy dolna czesc macierzy odleglosci
        for li2 = 1:li-1
            D_Map(li,li2) = sqrt((S_Map(li,1)-S_Map(li2,1))^2+(S_Map(li,2)-S_Map(li2,2))^2);
        end
        D_Map(li,li) = sqrt((S_Map(li,1)-BaseX)^2+(S_Map(li,2)-BaseY)^2); % na przekatnej, odleglosc wezla od punktu bazowego SINK
    end

    for li = 2:N    % teraz dol kopiujemy na gorna czesc macierzy odleglosciczesc macierzy odleglosci
        for li2 = 1:li-1
            D_Map(li2,li)=D_Map(li,li2);
        end
    end
    D_Map(N+1,N+1)=0;

    for li=1:N
        S_Map(li,6)= D_Map(li,li);
    end
    
end

